﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CpuSimulator.Instructions
{
    /// <summary>
    /// LUI (Load Upper Immediate)将立即数作为一个32位数的前20位，后12位补0，这样就形成了一个很大的数，将结果写入rd
    /// _________________________________________________________________________________________________________________________________________________
    /// |_________________立即数20位____________________________________________________________|_________rd,5位______|______OPCODE 7位____________|
    /// | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 |
    /// |                         imm[31:12]                                                                                            |        rd                      |            0110111                     |
    /// </summary>
    public class LUI : Instruction
    {
        public override void Execute(Cpu cpuinfo)
        {
            var newVal = this.Immediate << 12;
            cpuinfo.Registers[this.Rd].SetValue(newVal);
            cpuinfo.InvodeRegisterChange(this.Rd, newVal.ToString("X8"));
        }
    }
}
